package com.miaoxun.dao.provider;

import com.miaoxun.domain.entity.RoleMenu;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

public class RoleMenuProvider extends BaseProvider {

    public String batchSave(Map map) {
        List<RoleMenu> list = (List<RoleMenu>) map.get("list");
        StringBuilder sb = new StringBuilder();
        sb.append("INSERT INTO role_menu ");
        sb.append("(role_id, menu_id) ");
        sb.append("VALUES ");
        MessageFormat mf = new MessageFormat("(#'{'list[{0}].roleId}, #'{'list[{0}].menuId})");
        for (int i = 0; i < list.size(); i++) {
            sb.append(mf.format(new Object[]{i}));
            if (i < list.size() - 1) {
                sb.append(",");
            }
        }
        return sb.toString();

    }
}
